import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
@Injectable({
  providedIn: 'root'
})
export class RoleService {
  data='/Roles'
  constructor(private http: HttpClient) { }
  private createPaginationParams(currentPage: number, itemsPerPage: number): HttpParams {
    return new HttpParams()
      .set('page', currentPage.toString())
      .set('pageSize', itemsPerPage.toString());
  }// 创建分页参数
  getAllRoles(page:any ,pageSize:any,keyword?:any){
   const GetAllRoles = '/GetPagedRole'
    return this.http.get(environment.apiUrl+ this.data+GetAllRoles,{ params:{page,pageSize} })
  }
  fifterRoles(page:any ,pageSize:any,keyword?:any){
   const GetAllRoles = '/GetPagedRole'
    return this.http.get(environment.apiUrl+ this.data+GetAllRoles,{ params:{page,pageSize,keyword} })
  }

  UpdateRole(id:any ,data:any){
    const UpdateRole ='/UpdateRole'
    return this.http.put(environment.apiUrl+ this.data+UpdateRole,data,{params:{id}},)
  }
  CreateRole(data:any){
    const CreateRole ='/CreateRole'
    return this.http.post(environment.apiUrl+ this.data+CreateRole,data)
  }
  DeleteRoles(id:any){
    const DeleteRoles = '/DeleteRoles'
    const options = {
      body: id,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl+this.data+DeleteRoles,options);
  }
  AssignMenuToRole(roleId:any,data:any){
    const GetMenusByRole = '/Menu/AssignMenuToRole'
    return this.http.post(environment.apiUrl+GetMenusByRole,data,{params:{roleId}});
  }
 GetMenusByRole(roleName:any){
    const GetMenusByRole = '/Menu/GetMenusByRole'
    return this.http.get(environment.apiUrl+GetMenusByRole,{params:{roleName}});
 }
  EnableRoles(data:any){
    const EnableRoles = '/EnableRoles'
    return this.http.put(environment.apiUrl+ this.data+EnableRoles,data, { responseType: 'text' })
  }

  DisableRoles(data:any){
    const DisableRoles = '/DisableRoles'
    return this.http.put(environment.apiUrl+ this.data+DisableRoles,data, { responseType: 'text' })
  }
}
